import Vue from 'vue'
import App from './App.vue'
import singleSpaVue from 'single-spa-vue'
import routerList from './router'
import registerRouter from './util/registerRouter'

import singlespaSpa1 from './singlespaSpa1'
import eventRoot from './eventRoot'
 
Vue.config.productionTip = false
 
const appOptions = {
  el: '#singleChild1',
  render: h => h(App)
}

// 支持应用独立运行、部署，不依赖于基座应用
if (!window.singleMain) {
  delete appOptions.el
  appOptions.router = registerRouter('', routerList)
  singlespaSpa1('', eventRoot)
  Vue.prototype.eventRoot = eventRoot
  new Vue(appOptions).$mount('#app')
}
 
// 基于基座应用，导出生命周期函数
let vueLifecycle = ''

export function bootstrap ({ baseUrl, eventRoot }) {
  console.log('singleChild1 bootstrap', baseUrl)
  appOptions.router = registerRouter(baseUrl, routerList)
  singlespaSpa1(baseUrl, eventRoot)
  Vue.prototype.eventRoot = eventRoot
  vueLifecycle = singleSpaVue({
    Vue,
    appOptions
  })
  return vueLifecycle.bootstrap(() => {})
}
 
export function mount () {
  console.log('singleChild1 mount')
  return vueLifecycle.mount(() => {})
}
 
export function unmount () {
  console.log('singleChild1 unmount')
  return vueLifecycle.unmount(() => {})
}
